#include<arduino.h>

char serialData;
#define gpio 10
void setup() {
  Serial.begin(9600);
  pinMode(gpio, OUTPUT); //11引脚连接演示用LED
  digitalWrite(gpio, LOW);

}
 
void loop(){
  if( Serial.available()>0 ){ 
    
    serialData =  Serial.read();   
    
    if (serialData == '1' ) {  //接收到点亮LED指令
      Serial.print("Got command: ");  Serial.println(serialData); 
      Serial.println("LED-ON");
      
      digitalWrite(gpio, HIGH);  //点亮LED指令
    } 
    else if(serialData == '0' ){                     //接收到熄灭LED指令
      Serial.print("Got command: ");  
      Serial.println(serialData); 
      Serial.println("LED-OFF");

      digitalWrite(gpio, LOW);      //熄灭LED指令  
    } 
    else if(serialData == '2' ){                     //接收到熄灭LED指令
      Serial.print("Got command: ");  
      Serial.println(serialData); 
      Serial.println("LED-OFF");
      digitalWrite(gpio, HIGH);  //点亮LED指令
      delay(1000);        //延时一秒
      digitalWrite(gpio, LOW);      //熄灭LED指令  
    }  
    else if(serialData == '3' ){                     //接收到熄灭LED指令
      Serial.print("Got command: ");  
      Serial.println(serialData); 
      Serial.println("LED-OFF");
      digitalWrite(gpio, HIGH);  //点亮LED指令
      delay(2000);        //延时两秒
      digitalWrite(gpio, LOW);      //熄灭LED指令  
    }   
  }
}
